#include "connectmanager.h"

ConnectManager::ConnectManager(QObject *parent) :
    QObject(parent)
{    
    socket = new  QTcpSocket;
    socket->connectToHost("localhost",355);

    connect(socket, &QTcpSocket::connected,
            [=]()
    {
        qDebug()<<"Connection established.\n";
    });
    aboutHost();
}

ConnectManager::~ConnectManager()
{

}
void ConnectManager::dataReceiverSlot( const QByteArray &_o)
{
    socket->write(_o);
    qDebug()<<".\n";


}

void ConnectManager::aboutHost()
{
    QTcpSocket*  socket = new QTcpSocket;
    socket->connectToHost("ynikolenko.com", 8877);
    connect(socket, &QTcpSocket::connected,
            [=]()
    {
        qDebug()<<"Connection to DB-server established.";
        aboutHostInfoString.append("Host found.");
        emit hostStatusInfo(aboutHostInfoString.toUtf8());
        //qDebug()<<"Connection to DB-server established.\n";
    });
    connect(socket, &QTcpSocket::hostFound,
            [=]()
    {
        qDebug()<<"Host found.";
        aboutHostInfoString.append("Connection to DB-server established.\n");
    });
    socket->disconnectFromHost();
}
